package oct2013;

public class DivideTwoIntegers {
	public int divide(int n, int t) {
		int s = 1;
		if (n < 0 && t > 0 || n > 0 && t < 0)
			s = -1;
		long p = Math.abs(n * 1l);
		long q = Math.abs(t * 1l);
		int res = 0;
		int k = 0;
		while (p >> k >= q) {
			k++;
		}
		k--;
		while (k >= 0) {
			if (p >= q << k) {
				p -= q << k;
				res += 1 << k;
			}
			k--;
		}
		return res * s;
	}

}
